package baiwa.rta.security;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/*
 *
 * Kroekpong Sakulchai
 * File Name : SMSSystemUserDetails.java
 * Date : Feb 27, 2013 : Time : 8:48:05 AM
 * Description :
 *
 */

public class WebUserDetails implements UserDetails {

	private static final long serialVersionUID = -3781930066180957676L;

	private String username;
	private String password;
	private List<WebRole> roles;

	public WebUserDetails(String username, String password,
			List<WebRole> roles) {
		this.username = username;
		this.password = password;
		this.roles = roles;
	}

	public List<WebRole> getRoles() {
		return roles;
	}

	public void setRoles(List<WebRole> roles) {
		this.roles = roles;
	}

	public boolean isEnabled() {
		return true;
	}

	public boolean isAccountNonExpired() {
		return true;
	}

	public boolean isCredentialsNonExpired() {
		return true;
	}

	public boolean isAccountNonLocked() {
		return true;
	}

	public Collection<GrantedAuthority> getAuthorities() {

		List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();

		for (WebRole role : roles) {
			grantedAuthorities.add(new SimpleGrantedAuthority(role.getRole()));
		}
		return grantedAuthorities;
	}

	public String getPassword() {
		return password;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}
